clear,clc,close all
date = datestr(datetime, 'yymmdd'); 
load joint_cha.mat
X=['JOINT',num2str(date),'_p.src'];
diary (X);
disp('&ACCESS RVP');
disp('&REL 100');
disp('&PARAM EDITMASK = *');
disp('&PARAM TEMPLATE = C:\KRC\Roboter\Template\vorgabe');
disp('&PARAM DISKPATH = KRC:\R1\Program\liudong');
X=['DEF JOINT',num2str(date),'_p()'];
disp(X)%文件名
disp('DECL INT i');
disp(';FOLD INI;%{PE}');
disp(';FOLD BASISTECH INI');
disp('GLOBAL INTERRUPT DECL 3 WHEN $STOPMESS==TRUE DO IR_STOPM ( )');
disp('INTERRUPT ON 3 ');
disp('BAS (#INITMOV,0 )');
disp(';ENDFOLD (BASISTECH INI)');
disp(';FOLD USER INI');
disp(';Make your modifications here');
fprintf('\n');

disp(';ENDFOLD (USER INI)');
disp(';ENDFOLD (INI)');
fprintf('\n');

disp(';FOLD PTP HOME Vel=100 % DEFAULT;%{PE}%R 8.3.48,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:HOME, 3:, 5:100, 7:DEFAULT');
disp('$BWDSTART=FALSE');
disp('PDAT_ACT=PDEFAULT');
disp('FDAT_ACT=FHOME');
disp('BAS(#PTP_PARAMS,100)');
disp('$H_POS=XHOME');
disp('PTP XHOME ');
disp(';ENDFOLD');

for j=1:6
disp(['XP' num2str(2) '.A' num2str(j) '=XP' num2str(1) '.A' num2str(j)]);
end
for j=7:8
disp(['XP' num2str(2) '.E' num2str(j-6) '=XP' num2str(1) '.E' num2str(j-6)]);
end
fprintf(';FOLD PTP P2 CONT Vel=30 %% PDAT1 Tool[2]:Tool2 Base[1]:Base1;%%{PE}%%R 8.3.48,%%MKUKATPBASIS,%%CMOVE,%%VPTP,%%P 1:PTP, 2:P1, 3:C_DIS, 5:100, 7:PDAT1\n',i,i,i,i);
fprintf('$BWDSTART=FALSE\n');
fprintf('PDAT_ACT=PPDAT1\n',i);
fprintf('FDAT_ACT=FP1\n',i);
fprintf('BAS(#PTP_PARAMS,100)\n');
fprintf('PTP XP2 C_DIS\n',i);
fprintf(';ENDFOLD\n');
disp('For i = 1 TO 150')

    %%
for i=2:length(joint_cha)
% for i=2:204
    disp(['; ' ,num2str(i)]);
    for j=1:6
    if joint_cha(i,j)>0
    disp(['XP' num2str(2) '.A' num2str(j) '=XP' num2str(2) '.A' num2str(j) '+' num2str(joint_cha(i,j))]);
    elseif joint_cha(i,j)==0
    disp(['XP' num2str(2) '.A' num2str(j) '=XP' num2str(2) '.A' num2str(j) '+' num2str(joint_cha(i,j))]);
    else
    disp(['XP' num2str(2) '.A' num2str(j) '=XP' num2str(2) '.A' num2str(j)  num2str(joint_cha(i,j))]); 
    end
    end

    for j=7:8
    if joint_cha(i,j)>0
    disp(['XP' num2str(2) '.E' num2str(j-6) '=XP' num2str(2) '.E' num2str(j-6) '+' num2str(joint_cha(i,j))]);
    elseif joint_cha(i,j)==0
    disp(['XP' num2str(2) '.E' num2str(j-6) '=XP' num2str(2) '.E' num2str(j-6) '+' num2str(joint_cha(i,j))]);
    else
    disp(['XP' num2str(2) '.E' num2str(j-6) '=XP' num2str(2) '.E' num2str(j-6)  num2str(joint_cha(i,j))]); 
    end
    end

    disp([';FOLD PTP P' num2str(2) ' CONT Vel=100 % PDAT' num2str(2) ' Tool[2]:Tool2 Base[1]:Base1;%{PE}%R 8.3.48,%MKUKATPBASIS,%CMOVE,%VPTP,%P' num2str(2) ' :PTP, 2:P' num2str(2) ' , 3:C_DIS, 5:30, 7:PDAT' num2str(2)]);
    disp('$BWDSTART=FALSE');
    disp(['PDAT_ACT=PPDAT' num2str(2)]);
    disp(['FDAT_ACT=FP' num2str(2)]);
    disp('BAS(#PTP_PARAMS,30)');
    disp(['PTP XP' num2str(2) ' C_DIS']);
    disp(';ENDFOLD');

end
%%
    fprintf('ENDFOR\n')
disp(';FOLD PTP HOME  Vel= 30 % DEFAULT;%{PE}%MKUKATPBASIS,%CMOVE,%VPTP,%P1:PTP, 2:HOME, 3:, 5:100, 7:DEFAULT');
disp('$BWDSTART = FALSE');
disp('PDAT_ACT=PDEFAULT');
disp('FDAT_ACT=FHOME');
disp('BAS (#PTP_PARAMS,100 )');
disp('$H_POS=XHOME');
disp('PTP  XHOME');
disp(';ENDFOLD');
disp('END');
diary off;
